package com.jinjie.reids;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;

@Data
@Configuration
@Component
@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {
    // reids 地址
    private String host;
    // redis 端口号
    private Integer port;
    // Redis 密码
    private String password;
    // Redis 数据库
    private Integer database;
    //连接超时时间（毫秒）
    private int timeout;
    //集群模式
    private Cluster cluster;
    //哨兵模式
    private Sentinel sentinel;

    public static class Cluster {
        //集群节点列表
        private List<String> nodes;
        //最大重定向次数
        private Integer maxRedirects;

        public List<String> getNodes() {
            return nodes;
        }

        public void setNodes(List<String> nodes) {
            this.nodes = nodes;
        }

        public Integer getMaxRedirects() {
            return maxRedirects;
        }

        public void setMaxRedirects(Integer maxRedirects) {
            this.maxRedirects = maxRedirects;
        }
    }

    public static class Sentinel {
        // 哨兵节点列表
        private List<String> nodes;
        // 主节点名称
        private String master;
        // 哨兵服务密码，可能与Redis本身密码是不用的，具体在sentinel配置文件中配置
        private String password;

        public List<String> getNodes() {
            return nodes;
        }

        public void setNodes(List<String> nodes) {
            this.nodes = nodes;
        }

        public String getMaster() {
            return master;
        }

        public void setMaster(String master) {
            this.master = master;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
